<?php
/**
 * Abstract message object
 * 
 * @package stanza.message
 */
class Zend_Jabber_Stanza_Request_Message_Abstract extends Zend_Jabber_Stanza_Request_Abstract {
    // Message types
    const TYPE_CHAT = 'chat';
    
    // X events (ussend when sending message)
    const EVENT_OFFLINE = 'offline';
    const EVENT_DELIVERED = 'delivered';
    const EVENT_COMPOSING = 'composing';
    const EVENT_DISPLAYED = 'displayed';

    /**
     * Message node
     * 
     * @var DomElement
     */
    protected $messageNode;
    
    /**
     * Thread string
     * 
     * @var string
     */
    protected $thread;
    
    /**
     * Create new message object
     * 
     * @param Zend_Jabber_User $user Distant jabber user
     */
    public function __construct(Zend_Jabber_User $toUser, $thread = '') {       
        parent::__construct();
        
        $this->messageNode = $this->dom->createElement('message');
        $this->messageNode->setAttribute('to', $toUser->getJid());
        $this->messageNode->setAttribute('type', $this->getType());
        $this->messageNode->setAttribute('id', $this->getId());
        
        $this->thread = Zend_Jabber_Message_Thread::searchByString($thread);
        
        $threadNode = $this->dom->createElement('thread', $this->thread->toString());
        $this->messageNode->appendChild($threadNode);
        
        $this->dom->appendChild($this->messageNode);
    }
    
    /**
     * Get message thread string
     */
    public function getThread() {
        return $this->thread;
    }
}
?>